<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body class="list">
<div th:replace="include/head.html::html"></div>
<div class="layui-fluid layui-anim-upbit layui-anim">
    <div class="layui-card">
        <!--查询from 表单-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-hide">
            <div class="layui-form-item">
                <div class="layui-inline layui-hide">
                    <label class="layui-form-label">省份名</label>
                    <div class="layui-input-block">
                        <input type="text" name="provinceName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <!--表格中的数据 并不显示-->
        <div class="layui-card-body">
            <!--表格外部上侧的按钮-->
            <div style="padding-bottom: 10px;" class="tool-bar">
                <button class="layui-btn add-btn" data-type="addLayer" shiro:hasPermission="finance:add">添加</button>
            </div>
            <!--数据表格 -->
            <table id="table" lay-filter="table"></table>
            <!--表格每行的 的操作按钮 -->
            <script type="text/html" id="toolbar">
                {{#  if(d.status == 1 ){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="agree"
                   shiro:hasPermission="finance:agree"><i
                        class="layui-icon layui-icon-edit"></i>同意</a>
                    {{#  if(d.type == 1 ){ }}
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reject"
                       shiro:hasPermission="finance:reject"><i
                            class="layui-icon layui-icon-delete"></i>驳回</a>
                    {{#  } }}
                {{#  } }}
            </script>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="none">
    var table;
    layui.use(['jquery','table'], function () {
        table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#table'
            , id: 'table'
            , loading: true
            , method: 'post'
            , url: 'finance/page' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'numbers', title: '序号'}
                , {field: 'price', title: '金额'}
                , {field: 'type', title: '类型', templet: function (d) {
                        if (d.type == 1) {
                            return "提现";
                        } else if (d.type == 2) {
                            return "退款";
                        }
                    }}
                , {field: 'status', title: '状态', templet: function (d) {
                        if (d.status == 1) {
                            return "<button type=\"button\" class=\"layui-btn layui-btn-xs layui-btn-normal\">申请中</button>"
                        } else if (d.status == 2) {
                            return "<button type=\"button\" class=\"layui-btn layui-btn-xs layui-btn-normal\">已经同意</button>"
                        } else if (d.status == 3) {
                            return "<button type=\"button\" class=\"layui-btn layui-btn-xs layui-btn-danger\">驳回</button>"
                        }
                    }}
                , {field: 'userName', title: '真实姓名'}
                , {field: 'userAccount', title: '提现账户'}
                , {field: 'priceType', title: '账户类型', templet: function (d) {
                        if (d.priceType == 1) {
                            return "微信";
                        } else if (d.priceType == 2) {
                            return "支付宝";
                        }
                    }}
                , {field: 'reason', title: '原因'}
                , {field: 'createTime', title: '创建时间'}
                , {field: 'examineTime', title: '审核时间'}
                , {title: '操作', width: 300, align: 'center', toolbar: '#toolbar'}
            ]]
        });
        //监听搜索
        form.on('submit(search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {where: field});
        });
        //监听行工具事件
        //注：tool 是工具条事件名，table 是 table 原始容器的属性 lay-filter="对应的值"
        table.on('tool(table)', function (obj) {
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                editLayer({
                    title: '编辑',
                    url: 'finance/edit?oid=' + data.oid,
                    area: ['50%', '80%'],
                    back: callback
                });
            } else if (layEvent === 'del') {
                layer.confirm('确定删除此行吗？', function (index) {
                    $.post("finance/delBean", {oid: data.oid}, function (res) {
                        if (res.code === 0) {
                            layer.msg(res.msg);
                            table.reload('table');
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }else if(layEvent === 'agree'){
                layer.confirm('确定同意吗？', function (index) {
                    $.post("finance/agree", {oid: data.oid}, function (res) {
                        if (res.code === 0) {
                            layer.msg(res.msg);
                            table.reload('table');
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });
        layui.$(".add-btn").on('click', function () {
            var type = layui.$(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var active = {
            addLayer: function () {
                var add = editLayer({
                    title: '添加',
                    url: 'finance/edit',
                    area: ['50%', '80%'],
                    back: callback
                });
            }
        }
    });

    function callback(ifr, index, data) {
        var field = data.field;
        $.post("finance/saveOrUpdate", field, function (res) {
            if (res.code === 0) {
                top.layer.msg(res.msg);
                top.layer.close(index);
                table.reload('table');
            } else {
                top.layer.msg(res.msg);
            }
        });
    }
</script>
</body>
</html>
